import { defineConfig } from 'vite'
import path from 'path'
import externalGlobals from 'rollup-plugin-external-globals'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import {
  createStyleImportPlugin,
  ElementPlusResolve,
} from 'vite-plugin-style-import'

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '~/': `${path.resolve(__dirname, 'src')}/`
    },
  },
  // server: {

  //   proxy: {
  //     "/api": {
  //       target: "http://1.14.241.161:9099",
  //       changeOrigin: true
  //     },
  //   },
  // },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `

        @use "~/styles/element/index.scss" ;
        @use "~/styles/element/base.scss" as *;
         
        `
      },
    },
  },

  plugins: [
    vue(),
    Components({
      resolvers: [

        ElementPlusResolver({
          importStyle: "sass",
          directives: true,
          version: "2.1.5",
        }),
      ],
    }),
    AutoImport({
      resolvers: [ElementPlusResolver({
        exclude: new RegExp(/^(?!.*loading-directive).*$/)
      })],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),


    createStyleImportPlugin({
      resolves: [ElementPlusResolve()],
      libs: [
        {
          libraryName: 'element-plus',
          esModule: true,
          resolveStyle: (name: string) => {
            return `element-plus/theme-chalk/${name}.css`
          },
        },
      ]
    })
  ],

  build: {
    rollupOptions: {
      external: ['js-cookie']
    }
  }

})
